import { get, post, put, del } from '../utils/http/request';

/**
 * 获取预约列表
 * @param params 查询参数
 * @returns 预约列表数据
 */
export function getAppointmentList(params: PageQuery): Promise<ApiResponse<PageResult<Appointment>>> {
  return get('/appointment/list', params);
}

/**
 * 获取预约详情
 * @param id 预约ID
 * @returns 预约详情
 */
export function getAppointmentDetail(id: number): Promise<ApiResponse<Appointment>> {
  return get(`/appointment/${id}`);
}

/**
 * 创建预约
 * @param data 预约信息
 * @returns 创建结果
 */
export function createAppointment(data: {
  hospitalId: number;
  departmentId: number;
  doctorId: number;
  patientId: number;
  appointmentDate: string;
  appointmentTime: string;
}): Promise<ApiResponse<{ id: number; orderNo: string }>> {
  return post('/appointment/create', data);
}

/**
 * 取消预约
 * @param id 预约ID
 * @param reason 取消原因
 * @returns 取消结果
 */
export function cancelAppointment(id: number, reason: string): Promise<ApiResponse<null>> {
  return put(`/appointment/${id}/cancel`, { reason });
}

/**
 * 对医生和服务进行评价
 * @param id 预约ID
 * @param data 评价数据
 * @returns 评价结果
 */
export function rateAppointment(id: number, data: {
  doctorRating: number;
  serviceRating: number;
  comment: string;
}): Promise<ApiResponse<null>> {
  return post(`/appointment/${id}/rate`, data);
}

/**
 * 获取可预约时间段
 * @param doctorId 医生ID
 * @param date 日期，格式：YYYY-MM-DD
 * @returns 可预约时间段列表
 */
export function getAvailableTimeSlots(doctorId: number, date: string): Promise<ApiResponse<Array<{
  time: string;
  available: boolean;
  remaining: number;
  fee: number;
}>>> {
  return get('/appointment/timeslots', { doctorId, date });
}

/**
 * 获取患者列表
 * @returns 患者列表
 */
export function getPatientList(): Promise<ApiResponse<Patient[]>> {
  return get('/patient/list');
}

/**
 * 添加患者
 * @param data 患者信息
 * @returns 添加结果
 */
export function addPatient(data: Omit<Patient, 'id' | 'userId'>): Promise<ApiResponse<{ id: number }>> {
  return post('/patient/add', data);
}

/**
 * 修改患者信息
 * @param id 患者ID
 * @param data 患者信息
 * @returns 修改结果
 */
export function updatePatient(id: number, data: Partial<Omit<Patient, 'id' | 'userId'>>): Promise<ApiResponse<null>> {
  return put(`/patient/${id}`, data);
}

/**
 * 删除患者
 * @param id 患者ID
 * @returns 删除结果
 */
export function deletePatient(id: number): Promise<ApiResponse<null>> {
  return del(`/patient/${id}`);
}

/**
 * 设置默认患者
 * @param id 患者ID
 * @returns 设置结果
 */
export function setDefaultPatient(id: number): Promise<ApiResponse<null>> {
  return put(`/patient/${id}/default`);
} 